/**
 * Copyright (C), 2015-2019, XXX有限公司
 * FileName: DriverInformationServiceImpl
 * Author:   李毅
 * Date:     2019/10/22 16:28
 * Description: 业务实现类
 * History:
 * <author>          <time>          <version>          <desc>
 * 作者姓名           修改时间           版本号              描述
 */
package com.ymtms.applicationsystem.service.impl;

import com.ymtms.applicationsystem.dao.DriverInformationMapper;
import com.ymtms.applicationsystem.exception.SystemException;
import com.ymtms.applicationsystem.pojo.DriverInformation;
import com.ymtms.applicationsystem.service.DriverInformationService;
import com.ymtms.applicationsystem.vo.GridRequest;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * 〈一句话功能简述〉<br> 
 * 〈业务实现类〉
 *
 * @author 李毅
 * @create 2019/10/22
 * @since 1.0.0
 */
@Service
public class DriverInformationServiceImpl implements DriverInformationService {

    @Autowired
    DriverInformationMapper driverInformationMapper;

    @Override
    public void insertDriverInformation(DriverInformation driverInformation) {
        int row = driverInformationMapper.insert(driverInformation);
        if (row!=1){
            throw new SystemException("插入信息失败，请重试！");
        }
    }

    @Override
    public List<DriverInformation> findDriverInformationByCondition(String condition, GridRequest gridRequest) {
        Integer end = gridRequest.getLimit();
        Integer begin = (gridRequest.getPage()-1) * end;
        List<DriverInformation> driverInformations = driverInformationMapper.selectByCondition(condition,begin,end);
        if (driverInformations.isEmpty()){
            throw new SystemException("未查询到任何相关信息");
        }
        return driverInformations;
    }

    @Override
    public void deleteDriver(List<Integer> keys) {
        int row = driverInformationMapper.deleteByList(keys);
        if (row ==0){
            throw new SystemException("未能正确删除，请重试！");
        }
    }

    @Override
    public void deleteOne(Integer did) {
        int row = driverInformationMapper.deleteDriver(did);
        if (row ==0) {
            throw new SystemException("未能正确删除，请重试！");
        }
    }

    @Override
    public void updateDriver(DriverInformation driverInformation) {
        int row = driverInformationMapper.updateByPrimaryKey(driverInformation);
        if (row==0) {
            throw new SystemException("未能正确修改，请重试！");
        }
    }

}